/*
 * Copyright 2008 Mark Davidson.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.doofer.test

import org.doofer.*

class TypeUtilTest extends DooferBaseTest {

    def params = null
    def su = null
    def tu = null

    void setUp() {
        super.setUp()
        params = [username: username, password: password, repository: repository]
        su = new SessionUtil(params)
        tu = new TypeUtil()
    }

    void testGetChildTypes() {
        su.useSession { session ->
            def subTypes = tu.getChildTypes(typeName: 'dm_document', session: session)
            assert(subTypes)
            assert(subTypes.contains('dm_menu_system'))
            assert(subTypes.contains('dm_xml_config'))
            assertFalse(subTypes.contains('dm_document'))
            assertFalse(subTypes.contains('dm_user'))
        }
    }

    void testHasChildType() {
        su.useSession { session ->
            assertTrue(tu.hasChildType(typeName: 'dm_document', child: 'dm_menu_system',  session: session))
            assertTrue(tu.hasChildType(typeName: 'dm_document', child: 'dm_xml_config',  session: session))
            assertFalse(tu.hasChildType(typeName: 'dm_document', child: 'dm_document',  session: session))
            assertFalse(tu.hasChildType(typeName: 'dm_document', child: 'dm_user',  session: session))
        }
    }

    void testGetParentTypes() {
        su.useSession { session ->
            def parentTypes = tu.getParentTypes(session: session, typeName: 'dm_xml_config')
            assert(parentTypes)
            assert(parentTypes.contains('dm_document'))
            assert(parentTypes.contains('dm_sysobject'))
        }
    }

    void testHasParentType() {
        su.useSession { session ->
            assertTrue(tu.hasParentType(typeName: 'dm_menu_system', parent: 'dm_document',  session: session))
            assertTrue(tu.hasParentType(typeName: 'dm_menu_system', parent: 'dm_sysobject',  session: session))
            assertTrue(tu.hasParentType(typeName: 'dm_xml_config', parent: 'dm_document',  session: session))
            assertFalse(tu.hasParentType(typeName: 'dm_user', parent: 'dm_document',  session: session))
        }
    }

}